package day10;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;

public class RiceTest {

    // 获取测试数据
    private List<Rice> getRiceData() {
        List<Rice> rices = new ArrayList<>();
        rices.add(new Rice("籼稻", "湖南", 1.2, 120, "白色", 650.0, false));
        rices.add(new Rice("粳稻", "东北", 1.0, 150, "白色", 1200.0, true));
        rices.add(new Rice("杂交水稻", "湖南", 1.5, 130, "白色", 950.0, true));
        rices.add(new Rice("香米", "泰国", 1.1, 140, "白色", 500.0, false));
        rices.add(new Rice("糯米", "江苏", 0.9, 135, "白色", 550.0, false));
        rices.add(new Rice("黑米", "陕西", 1.0, 145, "黑色", 400.0, false));
        rices.add(new Rice("红米", "云南", 0.95, 138, "红色", 450.0, false));
        rices.add(new Rice("海水稻", "山东", 1.3, 125, "白色", 300.0, true));
        return rices;
    }

    @Test
    public void testRiceFilter() {
        List<Rice> rices = getRiceData();
        System.out.println("所有水稻: " + rices.size() + " 种");

        // 测试1: 过滤出杂交品种
        List<Rice> hybridRices = RiceFilter.filter(rices, Rice::isHybrid);
        System.out.println("\n杂交水稻数量: " + hybridRices.size());
        hybridRices.forEach(System.out::println);

        // 测试2: 过滤出高产量水稻(每亩产量>800公斤)
        List<Rice> highYieldRices = RiceFilter.filter(rices,
                rice -> rice.getYieldPerAcre() > 800);
        System.out.println("\n高产量水稻(>800kg/亩): " + highYieldRices.size());
        highYieldRices.forEach(System.out::println);

        // 测试3: 过滤出来自湖南的水稻
        List<Rice> hunanRices = RiceFilter.filter(rices,
                rice -> "湖南".equals(rice.getOrigin()));
        System.out.println("\n湖南产水稻: " + hunanRices.size());
        hunanRices.forEach(System.out::println);

        // 测试4: 映射获取所有水稻品种名称
        List<String> varieties = RiceFilter.map(rices, Rice::getVariety);
        System.out.println("\n所有水稻品种: " + varieties);

        // 测试5: 映射获取所有水稻产量
        List<Double> yields = RiceFilter.map(rices, Rice::getYieldPerAcre);
        System.out.println("\n所有水稻产量: " + yields);

        // 测试6: 复合条件过滤 - 来自湖南的杂交水稻
        Predicate<Rice> fromHunan = rice -> "湖南".equals(rice.getOrigin());
        Predicate<Rice> isHybrid = Rice::isHybrid;
        List<Rice> hunanHybridRices = RiceFilter.filter(rices,
                fromHunan.and(isHybrid));
        System.out.println("\n湖南产杂交水稻: " + hunanHybridRices.size());
        hunanHybridRices.forEach(System.out::println);
    }
}
